package com.ff.miaosha.controller;

import com.ff.miaosha.domain.MiaoshaUser;
import com.ff.miaosha.domain.OrderInfo;
import com.ff.miaosha.result.CodeMsg;
import com.ff.miaosha.result.Result;
import com.ff.miaosha.service.GoodsService;
import com.ff.miaosha.service.OrderService;
import com.ff.miaosha.vo.GoodsVo;
import com.ff.miaosha.vo.OrderDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("order")
public class OrderController {

    @Autowired
    OrderService orderService;

    @Autowired
    GoodsService goodsService;

    @RequestMapping("detail")
    @ResponseBody
    public Result<OrderDetailVo> info(MiaoshaUser user,
                                      @RequestParam("orderId") long orderid){
        if (user==null){
            return Result.error(CodeMsg.SESSION_ERROR);
        }
        OrderInfo order=orderService.getOrderById(orderid);
        if (order==null){
            return Result.error(CodeMsg.ORDER_NOT_EXIST);
        }
        long goodsId=order.getGoodsId();
        GoodsVo goods=goodsService.getGoodsVoByGoodsId(goodsId);
        OrderDetailVo vo=new OrderDetailVo();
        vo.setOrderInfo(order);
        vo.setGoodsVo(goods);
        return Result.success(vo);
    }
}
